package com.rc.saas.tenant.base;

import com.rc.saas.tenant.model.tenant.TenantRole;
import com.rc.saas.tenant.model.tenant.TenantUser;
import com.rc.saas.tenant.search.enterprise.EnterpriseSubMemberApplySearch;
import com.rc.saas.tenant.service.tenant.TenantRoleService;
import com.rc.saas.tenant.shiro.ShiroUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;

/**
 * Created by sven on 2018-07-11
 */
@Controller
public class TenantBaseController implements ApplicationContextAware {
    private ApplicationContext ac;
    //private String tenantCode; //运营商
    //private String tenantOperatorId;//二级运营商
    //private TenantUser sessionTenantUser;
    @Autowired
    private TenantRoleService tenantRoleService;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ac = applicationContext;
    }

    protected ApplicationContext getApplicationContext() {
        return ac;
    }

    protected <T> T getBean(String name) throws BeansException {
        return (T) ac.getBean(name);
    }

    /**
     * 取会话用户信息
     * @return
     */
    protected TenantUser getSessionTenantUser() {
        TenantUser user = ShiroUtils.getSessionUser();
        return user;
    }


    /**
     * 运营商
     * @return
     */
    //protected String getTenantCode() {
    //    TenantUser user = ShiroUtils.getSessionUser();
    //    if (user == null) {
    //        return null;
    //    } else {
    //        return user.getTenantCode();
    //    }
    //}

    /**
     * 二级运营商
     * @return
     */
    //protected String getTenantOperatorId() {
    //    TenantUser user = ShiroUtils.getSessionUser();
    //    if (user == null) {
    //        return null;
    //    } else {
    //        return user.getTenantOperatorId();
    //    }
    //}
}
